/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package RunnerGameStates;

/**
 *
 * @author yamit_alejandro
 */




import modelos.ModelConverter;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.controls.binding.KeyboardBinding;
import com.jme.light.PointLight;
import com.jme.math.*;
import com.jme.renderer.*;
import com.jme.scene.*;
import com.jme.scene.shape.Box;
import com.jme.scene.state.*;
import com.jme.scene.state.lwjgl.*;
import com.jme.system.DisplaySystem;
import com.jme.util.*;
import com.jme.util.export.binary.*;
import com.jmex.awt.swingui.JMEDesktopState;
import com.jmex.editors.swing.settings.*;
import com.jmex.game.*;
import com.jmex.game.state.*;
import com.jmex.model.converters.*;
import java.io.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.java.games.input.Keyboard;
import runner.*;
/**
 *
 * @author yamit_alejandro
 */
public class MacheteGameState  extends BasicGameState{
        private Spatial model;
        private StandardGame game;
        private MainMenuState mainMenu;
        DebugGameState dgs;
    public MacheteGameState(String nombre, Spatial modelo){
        super(nombre);
        model = modelo;
       // this.mainMenu = new MainMenuState();
       // this.mainMenu.setActive(true);
        DisplaySystem display = DisplaySystem.getDisplaySystem();
        int width = display.getWidth();
        int height = display.getHeight();
        final Camera cam = display.getRenderer().createCamera(display.getWidth(),
                display.getHeight());
        cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1, 1000);
        cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_X);
        cam.update();
        KeyBindingManager.getKeyBindingManager().set("w",
                KeyInput.KEY_W);
        KeyBindingManager.getKeyBindingManager().set("a",
                KeyInput.KEY_A);
        KeyBindingManager.getKeyBindingManager().set("s",
                KeyInput.KEY_S);
        KeyBindingManager.getKeyBindingManager().set("d",
                KeyInput.KEY_D);
        dgs = new DebugGameState() {

            @Override
            public void update(float tpf) {
                super.update(tpf);
                // Update the InputHandler
                if (input != null) {
                    input.update(tpf);
                    /** If toggle_pause is a valid command (via key p), change pause. */
                    if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                            "w", false)) {
                        cam.setLocation(cam.getLocation().add(new Vector3f(1.0f, 0.0f, 0.0f)));
                    }
                     if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                            "w", false)) {
                        cam.setLocation(cam.getLocation().add(new Vector3f(1.0f, 0.0f, 0.0f)));
                    }
                     if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                            "w", false)) {
                        cam.setLocation(cam.getLocation().add(new Vector3f(1.0f, 0.0f, 0.0f)));
                    }

                }

            }
        };
           // Spatial model = mainMenu.getControlPrincipal().getWasminton();

            model.setLocalScale (model.getLocalScale().mult(0.25f));
            model.setLocalTranslation(


             0f, 0f, -250f);
        Quaternion q = model.getLocalRotation().clone();

        q.fromAngleAxis(




             (float)Math.PI/2, Vector3f.UNIT_Y);
        q.fromAngleAxis(




             (





             float)-Math.PI/2, Vector3f.UNIT_X);
        model.setLocalRotation(q);

        model.updateWorldBound();
        model.updateRenderState();
        dgs.setActive(            true);
        /*BasicGameState modelState = new BasicGameState("Modelo");
        modelState.getRootNode().attachChild(ModelConverter.load3ds("E:/Desarrollo/archivos/3ds/modelo.3ds"));

        modelState.getRootNode().getChild(0).setLocalTranslation(0f, 0f, 0f);
        modelState.getRootNode().setLocalScale(3f);
        modelState.setActive(true);*/

        /*Future<Camera> future = GameTaskQueueManager.getManager().update(new Callable<Camera>() {

        public Camera call() throws Exception {
        DisplaySystem display = DisplaySystem.getDisplaySystem();
        int width = display.getWidth();
        int height = display.getHeight();
        Camera camera = display.getRenderer().createCamera(width, height);
        camera.setFrustumPerspective(45.0f, (float) width / (float) height, 1, 1000);
        return camera;
        }wwwwwwwwwwwwwww
        });*/

              // Lighting
        /** Set up a basic, default light. */
        PointLight light = new PointLight();
        light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );
        light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
        light.setLocation( new Vector3f( 100, 100, 100 ) );
        light.setEnabled( true );

        /** Attach the light to a lightState and the lightState to rootNode. */
        LightState lightState;
        lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        lightState.setEnabled( true );
        lightState.attach( light );

        dgs.getRootNode().setRenderState(lightState);


//this.getRootNode().setRenderState(currentCamara.getLightState() );
        CameraNode camNode = new CameraNode("Camera Node", cam);
        camNode.setLocalTranslation (new
        Vector3f (10f, 0, -10f));
        camNode.updateWorldData(0);
        camNode.attachChild(model);
        dgs.getRootNode().attachChild(camNode);
        dgs.getRootNode().updateGeometricState(0, true);
        dgs.getRootNode().updateRenderState();
        GameStateManager.getInstance().attachChild(dgs);
    }
        public void activar(boolean bol){
            dgs.setActive(bol);

        }

        public void setWasminton(Spatial was){
            model  = was;
        }


}





